﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace QueryGroupBuilder
{
    public partial class FrmCartezianProduct : Form
    {
        public FrmCartezianProduct()
        {
            InitializeComponent();
        }

        private void button_Multiply_Click(object sender, EventArgs e)
        {
            List<string> redSource = box1.GetList().ToList();
            List<string> blueSource = box2.GetList().ToList();
            IEnumerable<string> result = from red in redSource from blue in blueSource select red + blue;
            List<string> resultColor = result.ToList<string>();
            box3.SetList(resultColor);
        }

        private void button_SaveAsTxt_Click(object sender, EventArgs e)
        {
            IList<string> strs = box3.GetList();
            string path = GetPath();
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            FileInfo myFile = new FileInfo(path);
            StreamWriter sw = myFile.CreateText();


            foreach (string s in strs)
            {
                sw.WriteLine(s);
            }
            sw.Close();
            MessageBox.Show("ok");
        }

        private string GetPath()
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                return saveFileDialog1.FileName;
            }
            return null;
        }
    }
}
